package com.example.widgetcase.slice;

import com.example.widget_lib.widget.view.CircleButton;
import com.example.widgetcase.ResourceTable;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.element.PixelMapElement;

public class CircleBtnAbtivity extends BaseSlice implements CircleButton.Callback {

    private int STROKE_WIDTH = 2;
    private CircleButton mOrientationListener;
    CircleButton cameraCb;
    CircleButton audioCb;
    CircleButton videoCb;

    @Override
    public int getChildUIContent() {
        return ResourceTable.Layout_circle_btn;
    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        mOrientationListener = new CircleButton(this);
        mOrientationListener.setCallback(this);
        mOrientationListener.enable();

        videoCb = (CircleButton) findComponentById(ResourceTable.Id_videoCb);
        audioCb = (CircleButton) findComponentById(ResourceTable.Id_audioCb);
        cameraCb = (CircleButton) findComponentById(ResourceTable.Id_cameraCb);

        PixelMapElement  videoElement = new PixelMapElement(videoCb.getPixelMap());
        videoCb.setImageElement(videoElement);
        PixelMapElement audioElement = new PixelMapElement(audioCb.getPixelMap());
        audioCb.setImageElement(audioElement);
        PixelMapElement cameraElement = new PixelMapElement(cameraCb.getPixelMap());
        cameraCb.setImageElement(cameraElement);

        RgbColor rgbColor = new RgbColor();
        rgbColor.setBlue(0);
        rgbColor.setGreen(0);
        rgbColor.setRed(0);

        RgbColor rgbColor1 = new RgbColor();
        rgbColor1.setBlue(66);
        rgbColor1.setGreen(61);
        rgbColor1.setRed(252);

        RgbColor rgbColor2 = new RgbColor();
        rgbColor2.setBlue(80);
        rgbColor2.setGreen(214);
        rgbColor2.setRed(38);

        RgbColor rgbColor3 = new RgbColor();
        rgbColor3.setBlue(181);
        rgbColor3.setGreen(81);
        rgbColor3.setRed(63);
        videoCb.setStroke(STROKE_WIDTH, rgbColor);
        videoCb.setBackgroundDisabledColor(rgbColor1);
//        videoCb.setBackgroundNormalColor(rgbColor1);
//        videoCb.setImageResource(R.mipmap.call_answer_video);

        audioCb.setStroke(STROKE_WIDTH, rgbColor);
        audioCb.setBackgroundDisabledColor(rgbColor2);
//        audioCb.setBackgroundNormalColor(rgbColor2);
//        audioCb.setImageResource(R.mipmap.call_answer_audio);

        cameraCb.setStroke(STROKE_WIDTH, rgbColor);
        cameraCb.setBackgroundDisabledColor(rgbColor3);
//        cameraCb.setBackgroundNormalColor(rgbColor3);
//        cameraCb.setImageResource(R.mipmap.call_camera_on_normal);

    }

    @Override
    public void orientationChanged(int orientation, int previousOrientation) {
        updateButtons(orientation);
    }

    private void updateButtons(int orientation) {
//        var indicators = arrayOf<Rotatable>(videoCb,audioCb,cameraCb)
        videoCb.setOrientation(orientation * 90, true);
        audioCb.setOrientation(orientation * 90, true);
        cameraCb.setOrientation(orientation * 90, true);
//        ArrayList arrayList = new ArrayList<Rotatable>();
//        arrayList.add(videoCb);
//        arrayList.add(audioCb);
//        arrayList.add(cameraCb);
//        for (int i = 0; i <= arrayList.size(); i++) {
//            if (arrayList.get(i) != null) {
//                ((CircleButton) arrayList.get(i)).setOrientation(orientation * 90, true);
//            }
//        }
//        ArrayList arrayList = new ArrayList<Rotatable>(videoCb, audioCb, cameraCb);
//        for (indicator in indicators) {
//            if (indicator != null) {
//                indicator!!.setOrientation(orientation * 90, true);
//            }
//        }
    }
}
